package com.nhjf.dao.teachers;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.dao.BaseDao;
import com.nhjf.model.teachers.CoursesType;
import com.nhjf.pojo.qo.teachers.CoursesTypeQo;

@Repository
public class CoursesTypeDao extends BaseDao<CoursesType, CoursesTypeQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, CoursesTypeQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null) {
			if(StringUtils.isNotBlank(qo.getCoursesType())){
                criteria.add(Restrictions.like("coursesType", qo.getCoursesType(),MatchMode.ANYWHERE));
            }
			if(qo.getType()!=null) {
				 criteria.add(Restrictions.eq("type",qo.getType()));
			}
			if(qo.getpId()!=null) {
				 criteria.add(Restrictions.eq("pId",qo.getpId()));
			}
			if(qo.getCoursesId()!=null) {
				criteria.add(Restrictions.eq("id",qo.getCoursesId()));
			}
			 criteria.addOrder(Order.asc("sort"));
		}
		return criteria;
	}

	@Override
	protected Class<CoursesType> getEntityClass() {
		// TODO Auto-generated method stub
		return CoursesType.class;
	}

}
